menuList[4].onclick();


function getImgsFun(){
    let tbodyMenu = cl("tbodyMenu");
    axios({
        url:'/admin/system/findAllHead',
        method:'GET',
        })
        .then(data => {
            console.log(data.data.data[0][0]);
            tbodyMenu.innerHTML ="";
            let i=0;
            for(let key of data.data.data[0]){
                tbodyMenu.innerHTML += `
                <tr>
                    <td>${key.setting}</td>
                    <td><img src="${key.head}" name="${key.rotationId}" onclick="openImgWin()"></td>
                    <td>
                        <button class="btn paixuBtn">
                            <i class=" iconfont paixu"  name="${key.setting}" onclick="openSortWinFUn()"></i>
                        </button>
                    </td>
                </tr>
                    `
                    i++;
                }
        })
        .catch(err => {
            console.log(err);
        })
}
getImgsFun()

// 头像的操作
let rotationid;
// 预览头像
function fileFun(){
    let headimgBig = cl("headimgBig");
    let file = cl("file");
    let imgFile = file.files[0];
    let imgSrc = window.URL.createObjectURL(imgFile);
    headimgBig.setAttribute('src', imgSrc);
}
// 展示放大图像
function openImgWin(e){
    let headimgBig = cl("headimgBig");
    let changeImgWin = cl("changeImgWin");
    let covers = document.getElementsByClassName("covers")[0];
    e=e || window.event;
    var target=e.target || e.srcElement;
    let src = target.getAttribute("src");
    rotationid = target.getAttribute("name");
    changeImgWin.style.display ='block'
    covers.style.display ='block'
    headimgBig.src = src;
}
// 修改头像
function submitChangeImgFun(){
    console.log(rotationid);
    let file = cl("file");
    console.log(file.files[0]);
    var formData = new FormData()
    formData.append('image',file.files[0]);
    axios({
        url: `/admin/system/findAllHead?rotationId=${rotationid}`,
        data: formData,
        method: 'post'
    }).then((data) => {
        console.log(data)
        if(data.data.data.code==20000){
            explain({
                code:1,
                msg:"修改成功",
                time:3000
            })
            closeUSerFun()
            getImgsFun()
        }
    }).catch((err) => {
        console.log(err)
    })
}
// 关闭的操作
function closeUSerFun(){
    let covers = cl("covers");
    let changeImgWin = cl("changeImgWin");
    let sortWin = cl("sortWin");
    covers.style.display = 'none';
    changeImgWin.style.display = 'none';
    sortWin.style.display = 'none';
}

// 展开选择图片顺序窗口
function openSortWinFUn(e){
    e=e || window.event;
    var target=e.target || e.srcElement;
    let sortWin = cl("sortWin");
    let covers = cl("covers");
    let sorts = cl("sorts");
    let prePosition = cl("prePosition");
    newSortid=-1;
    sortid = target.getAttribute("name");
    console.log(sortid);
    sorts.innerHTML = '';
    prePosition.innerHTML = `
    当前图片位置：${sortid}
    `;
    for(let i=1;i<=5;i++){   
        if(i!=sortid){
            sorts.innerHTML +=`
            <span class="sortSpan" onclick="chooseSortIdFun()" name="${i}">${i}</span>
            `
        }
    }

    sortWin.style.display = 'block';
    covers.style.display = 'none';

}

// 选择序号
let sortid = -1;
let newSortid = -1;
function chooseSortIdFun(e){
    e=e || window.event;
    var target=e.target || e.srcElement;
    newSortid = target.getAttribute("name")
    let sortSpan=document.getElementsByClassName("sortSpan");
    for(let i=0;i<sortSpan.length;i++) {
        sortSpan[i].style.color="black"
        sortSpan[i].style.backgroundColor="#fff"
    }
    target.style.color="#fff";
    target.style.backgroundColor="#438Eb9"
}
// 提交新的排序
function submitSortFun(){
    let str = ['1', '2', '3', '4', '5']
    console.warn(newSortid);
    console.warn(sortid);
    if(newSortid==-1){
        explain({
            code:3,
            msg:"请选择图片新的顺序",
            time:3000
        })
    }else{
        str[sortid-1] = newSortid;
        str[newSortid-1] =sortid;
        str = str.toString();
        console.warn(str);
        axios({
            url:'/admin/system/rotationSort',
            method:'POST',
            params:{
               list:str
                }
            })
            .then(data => {
                if(data.data.code==20000){
                    closeUSerFun()
                    getImgsFun()
                    explain({
                        code:1,
                        msg:"排序成功",
                        time:3000
                    })
                }
            })
            .catch(err => {
                console.log(err);
        })
    }
}